package com.example.question3.client;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Mono;

import java.net.URI;
import java.util.concurrent.CountDownLatch;

/**
 * @author Pactera
 */
@Component
public class CoffeeClient {
    @Autowired
    RestTemplate restTemplate;



    public Object getCoffee(Long id){
        URI uri = UriComponentsBuilder.fromUriString("http://127.0.0.1:8080/coffee/{id}").build(id);
        Object coffee1 = restTemplate.getForObject(uri, Object.class);

        return coffee1;
    }

    @Autowired
    WebClient webClient;
    public Object getCoffeeByWebClient(Long id) throws InterruptedException {
        Mono<Object> objectMono = webClient.get().uri("/coffee/{id}",id).retrieve().bodyToMono(Object.class);


        return objectMono;
    }
}
